package com.kmist.xiakexing.utils.cmds;

import android.util.Log;

import com.kmist.xiakexing.interfaces.ILook;
import com.kmist.xiakexing.presenters.PlayerPresenter;
import com.kmist.xiakexing.tools.Chinesed;
import com.kmist.xiakexing.utils.GObject;
import com.kmist.xiakexing.utils.scene.NpcBean;
import com.kmist.xiakexing.utils.scene.PlayerBean;

import static com.kmist.xiakexing.utils.Color.CYN;
import static com.kmist.xiakexing.utils.Color.ENDL;
import static com.kmist.xiakexing.utils.Color.HIG;
import static com.kmist.xiakexing.utils.Color.HIW;
import static com.kmist.xiakexing.utils.Color.HIY;
import static com.kmist.xiakexing.utils.Color.MAG;
import static com.kmist.xiakexing.utils.Color.NOR;
import static com.kmist.xiakexing.utils.Color.RED;
import static com.kmist.xiakexing.utils.Color.YEL;

public class Look implements ILook {

    private static final String TAG = "LOOK";
    private static Look sInstance = null;
    public static Look getsInstance() {
        if(sInstance == null){
            synchronized (Look.class){
                sInstance = new Look();
            }
        }
        return sInstance;
    }

    static String tough_level_desc[] = {
                 "不堪一击",
                 "毫不足虑",
                 "不足挂齿",
                 "初学乍练",
                 "略知一二",
                 "粗通皮毛",
                 "初窥门径",
                 "勉勉强强",
                 "平平淡淡",
    };

    static String heavy_level_desc[]= {
        "极轻", "很轻", "不重", "不轻", "很重", "极重"
    };

    String gender_self(String sex){
        return "你";
    }

    String gender_pronoun(String sex){
        switch (sex){
            case "中性神":
            case "男性":
            case "无性":
                return "他";
            case "女性":
                return "她";
            case "雄性":
            case "雌性":
            default:
                return "它";
        }
    }

    private String description(GObject obj) {

        if(obj.isPlayer()){
            int per = 0;
            int age = 0;
            per = obj.getPer(); //这是做什么？
            age = obj.getAge();

            //if(obj.get youth) age = 14;
            if ( obj.getGender() == "男性" || obj.getGender() == "无性")
            {
                if (per >=40)
                    return HIW + "现在一派神人气度，仙风道骨，举止出尘。\n" + NOR + ENDL;
                if (per <= 39 && (per > 38))
                    return HIG + "现在神清气爽，骨格清奇，宛若仙人。\n" + NOR + ENDL;
                if (per <= 38 && (per > 37))
                    return HIG + "现在丰神俊朗，长身玉立，宛如玉树临风。\n" + NOR + ENDL;
                if (per <= 37 && (per > 36))
                    return HIG + "现在飘逸出尘，潇洒绝伦。\n" + NOR + ENDL;
                if (per <= 36 && (per > 35))
                    return HIG + "现在面如美玉，粉妆玉琢，俊美不凡。\n" + NOR + ENDL;
                if (per <= 35 && (per > 34))
                    return HIG + "现在丰神如玉，目似朗星，令人过目难忘。\n" + NOR + ENDL;
                if (per <= 34 && (per > 33))
                    return HIY + "现在粉面朱唇，身姿俊俏，举止风流无限。\n" + NOR + ENDL;
                if (per <= 33 && (per > 32))
                    return HIY + "现在双目如星，眉梢传情，所见者无不为之心动。\n" + NOR + ENDL;
                if (per <= 32 && (per > 31))
                    return HIY + "现在举动如行云游水，独蕴风情，吸引所有异性目光。\n" + NOR + ENDL;
                if (per <= 31 && (per > 30))
                    return HIY + "现在双眼光华莹润，透出摄人心魄的光芒。\n" + NOR + ENDL;
                if (per <= 30 && (per > 29))
                    return HIY + "生得英俊潇洒，风流倜傥。\n" + NOR + ENDL;
                if (per <= 29 && (per > 28))
                    return MAG + "生得目似点漆，高大挺俊，令人心动。\n" + NOR + ENDL;
                if (per <= 28 && (per > 27))
                    return MAG + "生得面若秋月，儒雅斯文，举止适度。\n" + NOR + ENDL;
                if (per <= 27 && (per > 26))
                    return MAG + "生得剑眉星目，英姿勃勃，仪表不凡。\n" + NOR + ENDL;
                if (per <= 26 && (per > 25))
                    return MAG + "生得满面浓髯，环眼豹鼻，威风凛凛，让人倾倒。\n" + NOR + ENDL;
                if (per <= 25 && (per > 24))
                    return MAG + "生得眉如双剑，眼如明星，英挺出众。\n" + NOR + ENDL;
                if (per <= 24 && (per > 23))
                    return CYN +"生得虎背熊腰，壮健有力，英姿勃发。\n" + NOR + ENDL;
                if (per <= 23 && (per > 22))
                    return CYN + "生得肤色白皙，红唇墨发，斯文有礼。\n" + NOR + ENDL;
                if (per <= 22 && (per > 21))
                    return CYN + "生得浓眉大眼，高大挺拔，气宇轩昂。\n" + NOR + ENDL;
                if (per <= 21 && (per > 20))
                    return CYN + "生得鼻直口方，线条分明，显出刚毅性格。\n" + NOR + ENDL;
                if (per <= 20 && (per > 19))
                    return CYN + "生得眉目清秀，端正大方，一表人才。\n" + NOR + ENDL;
                if (per <= 19 && (per > 18))
                    return YEL + "生得腰圆背厚，面阔口方，骨格不凡。\n" + NOR + ENDL;
                if (per <= 18 && (per > 17))
                    return YEL +"生得相貌平平，不会给人留下什么印象。\n" + NOR + ENDL;
                if (per <= 17 && (per > 16))
                    return YEL + "生得膀大腰圆，满脸横肉，恶形恶相。\n" + NOR + ENDL;
                if (per <= 16 && (per > 15))
                    return YEL + "生得獐头鼠须，让人一看就不生好感。\n" + NOR + ENDL;
                if (per <= 15 && (per > 14))
                    return YEL + "生得面颊深陷，瘦如枯骨，让人要发恶梦。\n" + NOR + ENDL;
                if (per <= 14 && (per > 13))
                    return RED + "生得肥头大耳，腹圆如鼓，手脚短粗，令人发笑。\n" + NOR + ENDL;
                if (per <= 13 && (per > 12))
                    return RED + "生得贼眉鼠眼，身高三尺，宛若猴状。\n" + NOR + ENDL;
                if (per <= 12 && (per > 11))
                    return RED + "生得面如桔皮，头肿如猪，让人不想再看第二眼。\n" + NOR + ENDL;
                if (per <= 11 && (per > 10))
                    return RED + "生得呲牙咧嘴，黑如锅底，奇丑无比。\n" + NOR + ENDL;
                if (per <= 10)
                    return RED + "生得眉歪眼斜，瘌头癣脚，不象人样。\n" + NOR + ENDL;
            }
            else
            {
                if (per >=40)
                    return HIW + "现在宛如玉雕冰塑，似梦似幻，已不再是凡间人物\n" + NOR + ENDL;
                if (per <= 39 && (per > 38))
                    return HIG + "现在美若天仙，不沾一丝烟尘。\n" + NOR + ENDL;
                if (per <= 38 && (per > 37))
                    return  HIG + "现在灿若明霞，宝润如玉，恍如神妃仙子。\n" + NOR + ENDL;
                if (per <= 37 && (per > 36))
                    return HIG + "现在气质美如兰，才华馥比山，令人见之忘俗。\n" + NOR + ENDL;
                if (per <= 36 && (per > 35))
                    return HIG + "现在丰润嫩白，樱桃小口，眉目含情，仿佛太真重临。\n" + NOR + ENDL;
                if (per <= 35 && (per > 34))
                    return HIG + "现在鲜艳妩媚，袅娜风流，柔媚姣俏，粉光脂艳。\n" + NOR + ENDL;
                if (per <= 34 && (per > 33))
                    return HIY + "现在鬓若刀裁，眉如墨画，面如桃瓣，目若秋波。\n" + NOR + ENDL;
                if (per <= 33 && (per > 32))
                    return HIY + "现在凤眼柳眉，粉面含春，丹唇贝齿，转盼多情。\n" + NOR + ENDL;
                if (per <= 32 && (per > 31))
                    return HIY + "现在眉目如画，肌肤胜雪，真可谓闭月羞花。\n" + NOR + ENDL;
                if (per <= 31 && (per > 30))
                    return HIY + "现在娇若春花，媚如秋月，真的能沉鱼落雁。。\n" + NOR + ENDL;
                if (per <= 30 && (per > 29))
                    return HIY + "生得闲静如姣花照水，行动似弱柳扶风，体态万千。\n" + NOR + ENDL;
                if (per <= 29 && (per > 28))
                    return MAG + "生得娇小玲珑，宛如飞燕再世，楚楚动人。\n" + NOR + ENDL;
                if (per <= 28 && (per > 27))
                    return MAG + "生得鸭蛋秀脸，俊眼修眉，黑发如瀑，风情万种。\n" + NOR + ENDL;
                if (per <= 27 && (per > 26))
                    return MAG + "生得削肩细腰，身材苗条，娇媚动人，顾盼神飞。\n" + NOR + ENDL;
                if (per <= 26 && (per > 25))
                    return MAG + "生得丰胸细腰，妖娆多姿，让人一看就心跳不已。\n" + NOR + ENDL;
                if (per <= 25 && (per > 24))
                    return MAG + "生得粉嫩白至，如芍药笼烟，雾里看花。\n" + NOR + ENDL;
                if (per <= 24 && (per > 23))
                    return CYN + "生得腮凝新荔，目若秋水，千娇百媚。\n" + NOR + ENDL;
                if (per <= 23 && (per > 22))
                    return CYN + "生得鲜艳妍媚，肌肤莹透，引人遐思。\n" + NOR + ENDL;
                if (per <= 22 && (per > 21))
                    return CYN + "生得巧笑嫣然，宛约可人。\n" + NOR + ENDL;
                if (per <= 21 && (per > 20))
                    return CYN + "生得如梨花带露，清新秀丽。\n" + NOR + ENDL;
                if (per <= 20 && (per > 19))
                    return CYN + "生得风姿楚楚，明丽动人。\n" + NOR + ENDL;
                if (per <= 19 && (per > 18))
                    return YEL + "生得肌肤微丰，雅淡温宛，清新可人。\n" + NOR + ENDL;
                if (per <= 18 && (per > 17))
                    return YEL + "生得虽不标致，倒也白净，有些动人之处。\n" + NOR + ENDL;
                if (per <= 17 && (per > 16))
                    return YEL + "生得身材瘦小，肌肤无光，两眼无神。\n" + NOR + ENDL;
                if (per <= 16 && (per > 15))
                    return  YEL + "生得干黄枯瘦，脸色腊黄，毫无女人味。\n" + NOR + ENDL;
                if (per <= 15 && (per > 14))
                    return YEL + "生得满脸疙瘩，皮色粗黑，丑陋不堪。\n"+ NOR + ENDL;
                if (per <= 14 && (per > 13))
                    return RED + "生得一嘴大暴牙，让人一看就没好感。\n" + NOR + ENDL;
                if (per <= 13 && (per > 12))
                    return RED + "生得眼小如豆，眉毛稀疏，手如猴爪，不成人样。\n" + NOR + ENDL;
                if (per <= 12 && (per > 11))
                    return RED + "生得八字眉，三角眼，鸡皮黄发，让人一见就想吐。\n" + NOR + ENDL;
                if (per <= 11 && (per > 10))
                    return RED + "生得歪鼻斜眼，脸色灰败，直如鬼怪一般。\n" + NOR+ ENDL;
                if (per <= 10)
                    return RED + "长得和无盐有点相似耶。"+ NOR + ENDL;
            }
        }
        /*
        else if (! obj->query("can_speak") && living(obj))
        {
            if (! obj->query_temp("owner"))
                return "是一只未被驯服的畜生，眼光里满是戒心和敌意。\n";
            else
                return "是一只被" + obj->query_temp("owner_name") +
                        "驯服的畜生，一副很温驯的样子。\n";
        }

        */

        return "";
    }

    public static String getdam(GObject me, GObject obj)
    {
        int level = 100;
        //level = obj.get_damage(); TODO
        level = level /50;
        if( level >= heavy_level_desc.length ){
            level = heavy_level_desc.length -1;
        }
        return heavy_level_desc[(int)level];
    }

    static String gettof(GObject me, GObject obj){
        //TODO
        int attack_points = 0;

        return tough_level(attack_points);
    }

    static String tough_level(int power){
        int lvl = 0;
        int rawlvl = 0;
        int grade = 1;

        if(power < 0){power = 0;}

        //rawlvl = (int) pow( (float) 1.0 * power, 0.3); TODO
        lvl = (rawlvl / grade);

        if( lvl >= tough_level_desc.length ){
            lvl = tough_level_desc.length - 1;
        }
        return tough_level_desc[((int) lvl)];
    }

    /**
     * 获取年龄描述
     * @param me
     * @param obj
     * @return
     */
    @Override
    public String look_info_age(GObject me, GObject obj) {

        int age = obj.getAge();
        String pro = (obj == me) ? gender_self(obj.getGender()) : gender_pronoun(obj.getGender());
        String out = "";

        if(obj.isCharacter() /* TODO &&obj.canspeak() */){
            // 是人物角色
            if (age >= 25 /*&& obj->query("special_skill/youth")*/)
                out += pro + "看不出年纪的大小，好像只有二十多岁。\n";
            else
            {
                if (age >= 200)
                    out += pro + "看起来年纪很大了，难以估计。\n";
                else if (age < 10)
                    out += pro + "看起来年纪尚幼。\n";
                else
                    out += pro  + "看起来有" + Chinesed.chinese_number(age / 10 * 10) + "多岁。\n";
            }
        }
        return out;
    }

    /**
     * 获取外貌描述
     * @param me
     * @param obj
     * @return
     */
    @Override
    public String look_info_description(GObject me, GObject obj) {

        String pro = (obj == me) ? gender_self(obj.getGender()) : gender_pronoun(obj.getGender());
        String out = "";
        String desc = "";
        desc = description(obj);
        if (desc != "")
            out += pro + desc;

        return out;
    }

    /**
     * 获取刺青描述
     * @param me
     * @param obj
     * @return
     */
    @Override
    public String look_info_tattoo(GObject me, GObject obj) {
        //TODO
        return "";
    }

    @Override
    public String look_info_damage(GObject me, GObject obj) {

        String pro = (obj == me) ? gender_self(obj.getGender()) : gender_pronoun(obj.getGender());
        String out = "";

        out += pro + "武功看起来好象";
        out += gettof(me,obj);
        out += ",";
        out +="出手似乎";
        out +=getdam(me,obj);
        out += "。\n";
        return out + ENDL;
    }

    @Override
    public String look_info_releation(GObject me, GObject obj) {

        String pro = (obj == me) ? gender_self(obj.getGender()) : gender_pronoun(obj.getGender());
        String out = "";

        if(obj.getId() == 0 /* TODO me.getCoupleId()*/){
            if(me.getGender() == "女性")
                out = pro + "就是你的夫君";
            else
                out = pro + "就是你的妻子";
        }else if(obj.isBrother(me)){
            if(obj.getGender() == "女性"){
                if(obj.getAge() > me.getAge()){
                    out = pro + "是你的义姐";
                }else{
                    out = pro + "是你的结义妹子";
                }
            }else{
                if(obj.getAge() > me.getAge()){
                    out = pro + "是你的结义兄长";
                }else{
                    out = pro + "是你的义弟";
                }
            }
        }
        /* TODO
        else if(obj != me && obj.getLeague() && obj.getLeagueName() == obj.getLeagueName()){
            out = pro + "和你均是" + obj.getLeagueName() + "的同盟勇士\n";
        }
        */
        if(out != "")
            out += ENDL;
        return out;
    }

    @Override
    public String look_info_family(GObject me, GObject obj) {
        //TODO
        String pro = (obj == me) ? gender_self(obj.getGender()) : gender_pronoun(obj.getGender());
        return pro + "是你的长辈.\n" + ENDL;
    }

    @Override
    public String look_info_equiped(GObject me, GObject obj) {
        //TODO
        return "";
    }


}
